package com.fp.m7.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "accounts")
public class Account extends EntityBase implements com.fp.m7.api.model.Account {
	private static final long serialVersionUID = -2850059047398024586L;

	private String username;
	private String password;

	private String description;
	private String status;

	private boolean enabled = true;

	private String nickname;
	private String avatarUrl;

	private List<Comment> comments = new ArrayList<Comment>();

	private Set<Follow> followedBy = new HashSet<Follow>();
	private Set<Follow> following = new HashSet<Follow>();

	public Account() {
	}

	@Column(unique = true, nullable = false, length = 100)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(length = 1000)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(length = 160)
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Column(nullable = false)
	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	@Column(unique = true, nullable = false, length = 50)
	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	@Column(unique = true, length = 100)
	public String getAvatarUrl() {
		return avatarUrl;
	}

	public void setAvatarUrl(String avatarUrl) {
		this.avatarUrl = avatarUrl;
	}

	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "author", fetch = FetchType.LAZY, orphanRemoval = true)
	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "followed", fetch = FetchType.LAZY, orphanRemoval = true)
	public Set<Follow> getFollowedBy() {
		return followedBy;
	}

	public void setFollowedBy(Set<Follow> followedBy) {
		this.followedBy = followedBy;
	}

	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "follower", fetch = FetchType.LAZY, orphanRemoval = true)
	public Set<Follow> getFollowing() {
		return following;
	}

	public void setFollowing(Set<Follow> following) {
		this.following = following;
	}

	@Override
	public String toString() {
		return new StringBuilder("Account [id=").append(id) //
				.append("; username=").append(username) //
				.append("; nickname=").append(nickname) //
				.append("; url=").append(avatarUrl) //
				.append("; auditCD=").append(auditCD) //
				.append("]").toString();
	}
}
